#define _CRT_SECURE_NO_WARNINGS

#include<stdio.h>

int cmp(const void* a, const void* b)
{
    return *(int*)a - *(int*)b;
}
int firstMissingPositive(int* nums, int numsSize)
{
    for (int i = 0; i < numsSize; i++)
    {
        if (nums[i] < 0)
            nums[i] = numsSize + 1;
    }
    qsort(nums, numsSize, sizeof(nums[0]), cmp);
    int i = 0;
    for (i = 0; i < numsSize; i++)
    {
        if (nums[0] > 1)
            return 1;
        if (i != numsSize - 1 && nums[i] + 1 != nums[i + 1] && nums[i] != nums[i + 1])
        {
            if ((nums[i] + 1) != 0)
                return nums[i] + 1;
        }
    }

    return nums[numsSize - 1] + 1;
}